//
//  STDSShapenStrokeEffect.h
//  STDSRenderSDKIOS
//
//  Created by 陈学明 on 2023/3/27.
//

#ifndef STDSShapenStrokeEffect_h
#define STDSShapenStrokeEffect_h

#include "STDSBaseEffect.hpp"
#include <Basic/Attrib/STDSAttribStroke.hpp>
#include <Basic/Path/STDSPath.hpp>

/// 形状描边效果
class STDSShapenStrokeEffect: public STDSBaseEffect {
public:
    STDSShapenStrokeEffect() {
        mEffectType = STDSEffectTypeStroke;
    }
    ~STDSShapenStrokeEffect() {
//        printf("dealloc--STDSTintEffect\n");
    }
    void initGL() override {
        STDSBaseEffect::initGL();
//        mStrokeProgram = mContext->getProgram(kShaderSRCDarkAngle);
    }
    
    void setPath(shared_ptr<STDSPath> path) {
        mPath = path;
    }
    
public:
    void draw() override {
        mStrokeProgram->use();
        if (mTexture != nullptr) {
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, mTexture->getId());
            mStrokeProgram->setUniform(mStrokeProgram->getUniform("uTexture"), 0);
        }
        mAtbRect.setPosVex(mStrokeProgram->getAttrib("aPos"));
        mAtbRect.setPosTex(mStrokeProgram->getAttrib("aTexCoord"));
        mAtbRect.draw();
        mStrokeProgram->unuse();
    }

private:
    shared_ptr<STDSPath> mPath{nullptr};
    STDSAttribStroke mStrokeAttrib;
    shared_ptr<STDSShaderProgram> mStrokeProgram{nullptr};
};
#endif /* STDSShapenStrokeEffect_h */
